#pragma once
/*
A class to define the entire game world.
*/
#include <Windows.h>
#include <stdio.h>
#include <stack>
#include "Location.h"
#include "Map_Cell.h"
#include "Colors.h"


#define MAP_DEFAULT_WIDTH	79
#define MAP_DEFAULT_HEIGHT	40
#define ROOM_SIZE_VARIANCE	2 + rand() % 3

class Map
{
private:
	//int m_currentLayer;	//The current dungeon level
	Map_Cell ** m_layer;	//2D Map_Cell array for the current level
	int width, height;
	bool m_redrawMap;

public:
	Map();  //Default Constructor
	~Map();	//Destructor

	//Game Loop functions
	void handleInput(char a_input);
	void updateMap(int a_x, int a_y);
	void draw();
	std::stack<Location> Map::drawCircle(int a_xCenter, int a_yCenter, int a_radius){
		//A holder for our collected tiles
		std::stack<Location> temp;
		//TODO: Figure out what these mean
		int f = 1 - a_radius;
		int ddF_x = 1;
		int ddF_y = -2 * a_radius;
		//The x/y location of the cell to plot
		int x = 0;
		int y = a_radius;
		//Draw the first 4 cardinal points
		temp.push(m_layer[a_yCenter + a_radius][a_xCenter]);
		temp.push(m_layer[a_yCenter - a_radius][a_xCenter]);
		temp.push(m_layer[a_yCenter][a_xCenter + a_radius]);
		temp.push(m_layer[a_yCenter][a_xCenter - a_radius]);

		while(x < y){		//TODO: Figure out why this loop works
			if(f >= 0){
				y--;
				ddF_y += 2;
				f += ddF_y;
			}
			x++;
			ddF_x += 2;
			f += ddF_x;
			//Draw for each of the seperate octants
			temp.push(m_layer[a_yCenter + y][a_xCenter + x]);
			temp.push(m_layer[a_yCenter + y][a_xCenter - x]);
			temp.push(m_layer[a_yCenter - y][a_xCenter + x]);
			temp.push(m_layer[a_yCenter - y][a_xCenter - x]);
			temp.push(m_layer[a_yCenter + x][a_xCenter + y]);
			temp.push(m_layer[a_yCenter + x][a_xCenter - y]);
			temp.push(m_layer[a_yCenter - x][a_xCenter + y]);
			temp.push(m_layer[a_yCenter - x][a_xCenter - y]);
		}
		return temp;	//Return
	}
	void redraw();	//A request to redraw the map;
	void redrawAt(int a_x, int a_y);	//A request to redraw a single space on the map

	//Accessors
	char getLocationAt(int a_x, int a_y);

	//Misc Methods
	void generateDungeon(int a_NumOfNodes, int a_NumOfRooms);	//@Param1:  The number of random points to generate.  @Param2:  The number of those point that will be changed to rooms (Param2 will be forced equal-to Param1 if greater)
};